package bt.sim.login;

import com.jfinal.core.Controller;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.StrKit;

public class LoginController extends Controller {

	public void index() {
		render("login.jsp");
	}
	
	public void check() {
		User user = getModel(User.class);
		setAttr("user", user);
		if(StrKit.isBlank(user.getStr("userName")) || StrKit.isBlank(user.getStr("password"))) {
			setAttr("error", "用户名或密码为空！");
			render("login.jsp");
			return;
		}
		User currentUser = User.me.findUser(user);
		if(currentUser == null) {
			setAttr("error", "用户名或密码错误！");
			render("login.jsp");
		} else {
			setSessionAttr("currentUser", currentUser);
			redirect("/view/main.jsp");//绝度路径和相对路径的区别
		}
	}
}
